package workSheets;

import java.util.Scanner;

public class workSheet0 {
    public static void main(String[] args) {
        String hostName = "2018143146 Saxon Mo";
        System.out.println("this is my information:" + hostName);
        for (int i = 0; i < 2; i++) {//input information 10 times
            boolean flag = true;
            String useName = null;
            while (flag) {
                System.out.println("Input your English name :");
                Scanner scan = new Scanner(System.in);
                useName = scan.nextLine();
                if (check(useName)) {//check the name must made of [a-zA-Z],if not, input again
                    flag = false;
                } else {
                    System.out.println("Input your name again");
                }
            }
            System.out.println(useName + "\t" + "Good Morning");
        }
        System.out.println("How many times the message should be displayed");
        boolean flag = true;
        int times = 0;
        while (flag) {
            Scanner scan1 = new Scanner(System.in);
            String s = scan1.nextLine();
            try {
                times=Integer.parseInt(s);
            }catch (Exception e){
                System.out.println("Input type must Integer");
            }
            if (check(times)){
                flag=false;
            }else{
                flag=true;
                System.out.println("input times again");
            }
        }
        System.out.println("times:" + times);

    }

    public static boolean check(String name) {
        if (name == null||name.length()>=20) {
            System.out.println("input error!");
            return false;
        } else if (name.contains("[0-9]")) {
            return false;
        } else return name.matches("[a-zA-Z]+");
    }

    public static boolean check(int times) {
        if (times >= 20 || times <= 0) {
            System.out.println("input error!");
            return false;
        } else return true;
    }
}
